package aptean外资公司笔试;
//题1
public class reverse {
    public static void main(String[] args) {
        System.out.println(fun(224));
    }

    public static int fun(int a){
        if (!check(a))return 0;
        boolean flag = a > 0;
        int num = a > 0 ? a : -a;
        int sum = 0;
        int tail;
        while (num > 0) {
            tail = num%10;
            sum=sum*10+tail;
            num/=10;
        }
        //System.out.println(sum);
        if (!flag)return -sum;
        return sum;
    }

    public static boolean check(int a){
        int num = a > 0 ? a : -a;
        int sum=a > 0 ? 0 : 1;
        int count=1; //记录2进制位数 加一个符号位
        while (num>1){ //转换2进制 sum (倒序)
            if (count+1>=32)return false;
            count++;
            if (num%2 == 1){
                sum = sum*10 + 1;
            }else {
                sum = sum*10;
            }
            num = num/2;
        }
        sum=sum*10+1;
        count++;//末尾 1
        System.out.println(sum+":"+count);

        return true;
    }
}
